package org.example.booksystem.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class TimeRecordAspect {

     @Around("execution(* org.example.booksystem.controller.*.*(..))")

     public Object record(ProceedingJoinPoint pj) throws Throwable {

          long start = System.currentTimeMillis();
          Object result =  pj.proceed();   // 继续执行目标方法 ,记录返回结果
          log.info(pj.getSignature()+"cost time: "+ (System.currentTimeMillis()-start) + "ms");
          return result ;
     }
}
